import systemApi from "@rc/apis/rc/system.mjs";

import filtrates from "./filtrates.mjs";

import AccountEditDialog from "./components/account-edit-dialog.vue";

export default {
	components: { AccountEditDialog },
	data() {
		return {
			filtrates,
			isLoading: false, // 页面加载状态
			isShowAccountDialog: false, //账号编辑弹窗展示状态
			editId: "", // 当前编辑的账号id
			// 筛选器配置项
			searchParams: {}, // 当前的筛选项信息
			tableList: [], // 表格数据
			page: {
				// 分页数据
				pageIndex: 1,
				pageSize: 10,
				pageCount: 0
			}
		};
	},
	methods: {
		// 根据当前检索条件查询表格数据
		queryTableData() {
			this.isLoading = true;
			systemApi.queryUploadAccountList({
				data: {
					pageSize: this.page.pageSize,
					pageIndex: PageUtil.getStartIndex(this.page),
					...this.searchParams
				},
				success: ({ count, data }) => {
					this.selectItems = [];
					this.tableList = data;
					this.page.pageCount = count;
				},
				complete: () => {
					this.isLoading = false;
				}
			});
		},
		// 筛选搜索
		filterSubmit(params) {
			this.searchParams = params;
			this.queryTableData();
		},
		// 点击删除
		onDelete(relationId) {
			this.$confirm("确定要删除账号对应关系吗?删除后该保利账号上传的视频同步至平台时无上传人信息!", "提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning",
				callback: (action) => {
					if (action === "confirm") {
						systemApi.delUploadAccount({
							data: { relationId },
							success: () => {
								this.$message.success("删除成功");
								this.queryTableData();
							}
						});
					}
				}
			});
		}
	},
    created() {
        PermissUtil.checkPagePermiss("rc/system/account-list");
    }
};
